package com.gg.tsj.service.impl;


import com.gg.common.pojo.SCell;
import com.gg.common.pojo.SGather;
import com.gg.common.pojo.SGatherDetails;
import com.gg.hj.util.INumber;
import com.gg.tsj.mapper.SGatherXiaotanMapper;
import com.gg.tsj.service.SGatherService;
import com.gg.tsj.vo.PageVo;
import com.gg.tsj.vo.SGatherVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class SGatherServiceImpl implements SGatherService {

    @Resource
    private SGatherXiaotanMapper sGatherXiaotanMapper;
    @Resource
    private INumber iNumber;

    @Override
    public void saves(SGatherVo SGatherVo) throws Exception {
        ;
        SGatherVo.setGatherId(iNumber.number("401"));
//        SGatherVo.setCheckTag("S001-0");
//        SGatherVo.setStoreTag("K002-1");
        this.sGatherXiaotanMapper.saveSGather(SGatherVo);
        System.out.println(SGatherVo.getId());
        this.sGatherXiaotanMapper.saveSGatherDetails(SGatherVo);
    }


    @Override
    public PageVo<SGather> querySGather(PageVo<SGather> vo) throws Exception {
        PageHelper.startPage(vo.getCurrentPage(),vo.getPageSize());
        List<SGather> SGatherList = this.sGatherXiaotanMapper.querySGatherFY(vo.getConditions());
        PageInfo<SGather> studentVoPageInfo = new PageInfo(SGatherList);

        PageVo pageVo=new PageVo();
        pageVo.setTotal(studentVoPageInfo.getTotal());
        pageVo.setRows(studentVoPageInfo.getList());

        return pageVo;
    }

    @Override
    public SGatherVo querySGatherDetails(int id) throws Exception {
        SGatherVo sGatherVo = this.sGatherXiaotanMapper.querySGather(id);
        List<SGatherDetails> sGatherDetails = this.sGatherXiaotanMapper.querySGatherDetails(id);
        sGatherVo.setList(sGatherDetails);
        return sGatherVo;
    }

    @Override
    public void UpdateAudit(SGatherVo vo) throws Exception {
        this.sGatherXiaotanMapper.UpdateAudit(vo);
    }

    @Override
    public PageVo<SGather> querySGatherPage(PageVo<SGather> vo) throws Exception {
        PageHelper.startPage(vo.getCurrentPage(),vo.getPageSize());
        List<SGather> SGatherList = this.sGatherXiaotanMapper.querySGatherPage(vo.getConditions());


        PageInfo<SGather> studentVoPageInfo = new PageInfo(SGatherList);
        PageVo pageVo=new PageVo();
        pageVo.setTotal(studentVoPageInfo.getTotal());
        pageVo.setRows(studentVoPageInfo.getList());

        return pageVo;

    }

    @Override
    public SCell queryByProductIdKey(String pid) throws Exception {
        return this.sGatherXiaotanMapper.queryByProductIdKey(pid);
    }

    @Override
    public void updateS_GATHER_DETAILS(int id) throws Exception {
        //jjjj
        this.sGatherXiaotanMapper.updateS_GATHER_DETAILS(id);
    }

    @Override
    public PageVo<SGather> querySGatherPage_develop(PageVo<SGather> vo) throws Exception {
        PageHelper.startPage(vo.getCurrentPage(),vo.getPageSize());
        List<SGather> SGatherList = this.sGatherXiaotanMapper.querySGatherPage_develop(vo.getConditions());

        PageInfo<SGather> studentVoPageInfo = new PageInfo(SGatherList);
        PageVo pageVo=new PageVo();
        pageVo.setTotal(studentVoPageInfo.getTotal());
        pageVo.setRows(studentVoPageInfo.getList());
        return pageVo;
    }

    @Override
    public PageVo<SGather> queryStorage(PageVo<SGather> vo) throws Exception {
        PageHelper.startPage(vo.getCurrentPage(),vo.getPageSize());
        List<SGather> SGatherList = this.sGatherXiaotanMapper.queryStorage(vo.getConditions());

        PageInfo<SGather> studentVoPageInfo = new PageInfo(SGatherList);
        PageVo pageVo=new PageVo();
        pageVo.setTotal(studentVoPageInfo.getTotal());
        pageVo.setRows(studentVoPageInfo.getList());
        return pageVo;

    }

    @Override
    public void updateSGatherDetailsQuantityOfThisTime(SGatherVo vo) throws Exception {

        this.sGatherXiaotanMapper.updateSGatherDetailsQuantityOfThisTime(vo);
        this.sGatherXiaotanMapper.updateSGathersToreTag(vo.getGatherId());

    }

    @Override
    public void updateSGatherDetailsGATHERED_AMOUNT(SGatherVo vo) throws Exception {
       for(int i=0;i<vo.getList().size();i++){
           this.sGatherXiaotanMapper.updateS_CELLAMOUNT(vo.getList().get(i));
       }


        this.sGatherXiaotanMapper.updateSGatherDetailsGATHERED_AMOUNT(vo);
        this.sGatherXiaotanMapper.updateSGatherDetailsGatherTag(vo);
        this.sGatherXiaotanMapper.updateWarehousingRegistration(vo.getGatherId());
        this.sGatherXiaotanMapper.updateS_GATHERMOUNT(vo);
        int i = this.sGatherXiaotanMapper.querygather_tag(vo.getGatherId());
        System.out.println(i+"---------------------");
        if (i==0){
            this.sGatherXiaotanMapper.updateS_GATHER_attemperTimeupdateS_GATHER_attemperTime(vo);
            this.sGatherXiaotanMapper.updateByToreTag(vo.getGatherId());
        }
    }


    @Override
    public PageVo<SGather> queryAudit(PageVo<SGather> vo) throws Exception {
        PageHelper.startPage(vo.getCurrentPage(),vo.getPageSize());
        List<SGather> SGatherList = this.sGatherXiaotanMapper.queryAudit(vo.getConditions());

        PageInfo<SGather> studentVoPageInfo = new PageInfo(SGatherList);
        PageVo pageVo=new PageVo();
        pageVo.setTotal(studentVoPageInfo.getTotal());
        pageVo.setRows(studentVoPageInfo.getList());
        return pageVo;
    }


}
